#!/usr/bin/env node

const Koa = require('koa'),
      Router = require('koa-router'),
      bodyparser = require('koa-bodyparser'),
      log = console.log;
const app = new Koa(),
      router = new Router();

app.use(bodyparser());
app.use(((ctx,next) => {
      log(`${ctx.method}`);
      next();
}))
router.prefix('/api/authors');
router.get('/',async (ctx)=>{
  const { page,limit } = ctx.query;
  log(ctx.request.headers['user-agent']);
 ctx.body = `分页查询漫画书作者,page=${page} & limit=${limit}`;
});
router.get('/:authorName',async (ctx)=>{
  const {authorName} = ctx.params;
  log(ctx.request.headers);
  ctx.body = `按名称查询漫画书作者,authorName=${authorName}`;
});
router.post('/',async (ctx) => {
  const {name} = ctx.request.body;
  ctx.body = `添加漫画书作者,authorName = ${name}`;
})
router.put('/:id',async (ctx) => {
  ctx.body = '修改漫画书作者';
})
router.delete('/:id',async (ctx) => {
  ctx.body = '删除漫画书作者';
})
app.use(router.routes());
app.listen(3000);
